<?php

//个人中心控制器
class GerenController extends LoginController{
	
	public function index(){
		//检测SESSION ID是否存在
		if(!$_SESSION['uid']){
			$this->success('请先完成登陆',U('Index/Login/denglu'));
		}
		$data=K('Login')->where("uid={$_SESSION['uid']}")->find();
		$this->assign('data',$data);
		
		
		//显示订单
		$shang=M()->join("__shoplist__ sl JOIN __shopcat__ sc ON sl.slid=sc.slid")->where("uid={$_SESSION['uid']}")->all();
		foreach ($shang as $k => $v) {
			$shang[$k]['options']=explode(',', $v['options']);
			$shang[$k]['img']=K('Detail')->where("gid={$v['gid']}")->getField('medium');
			$shang[$k]['gname']=K('Goods')->where("gid={$v['gid']}")->getField('gname');
		}
		foreach ($shang as $k => $v) {
	    	foreach ($v['options'] as $kk => $vv) {
	    		   $kk=M()->join("__attr__ a JOIN __goods_attr__ ga ON a.taid=ga.taid")->where("gtid={$vv}")->getField('taname',true);
				   $kk=implode($kk);
				   $da=K('Goodsattr')->where("gtid={$vv}")->getField('gtvalue',true);
				   $shang[$k]['attrSpec'][$kk]=$da;
	    	}
	    }
		p($shang);
		$this->assign('shang',$shang);
		$this->display();
	}
	
	//上传图片
	public function upload(){
	     $upload = new Upload('Upload/Content/' . date('y/m'));
		 $file = $upload->upload();
		 if (empty($file)) {
		 	$this->ajax('上传失败');
		 } else {
		 	$data = $file[0];
			$this->ajax($data);
		 }
	}
	
	public function edit(){
		if(IS_POST){
			$userData=Q('post.');
			$data=array(
			  'jian' => $userData['jian'],
			  'sex' => $userData['sex'],
			  'birthday' => $userData['birthday'],
			  'hearimg' => $userData['thumb_list'],
			  'zname' => $userData['zname'],
			);
			
			K('Login')->where("uid={$_SESSION['uid']}")->update($data);
			$this->success('保存成功',U('Index/Index/index'));
		}
	}
	
	public function paedit(){
		if(IS_POST){
			$post=Q('post.oldpasswd');
			$oldpawd=K('Login')->where("uid={$_SESSION['uid']}")->find();
			$password=$oldpawd['password'];
			if($post != $password){
				$this->error('当前密码不正确');
			}
			
			$passwd=md5(Q('post.newpasswd'));
			$arr=array(
			  'password'=>$passwd,
			);
			K('Login')->where("uid={$_SESSION['uid']}")->update($arr);
			$this->success('保存成功',U('Index/Geren/index'));
		}
		
	}
	
	
	
}






?>